package com.lz.football.module.ladderMatch.item
{
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;
	
	public class LadderLvTabMenu extends Sprite implements IComponent
	{
		/**
		 *d级  1
		 */
		public static const D_TYPE:String = "D";
		/**
		 *c级 2 
		 */
		public static const C_TYPE:String = "C";
		/**
		 *b级 3; 
		 */
		public static const B_TYPE:String = "B";
		/**
		 *a级 4; 
		 */
		public static const A_TYPE:String = "A";
		/**
		 *s级 5; 
		 */
		public static const S_TYPE:String = "S";
		
		
		
		private var symbolSkin:MovieClip;
		private var _dBtn:LButton;
		private var _cBtn:LButton;
		private var _bBtn:LButton;
		private var _aBtn:LButton;
		private var _sBtn:LButton;
		public var selectBtn 	:LButton;//选择的btn
		public var selectType 	:String;//选择类型
		public function LadderLvTabMenu()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
			_dBtn = new LButton(symbolSkin._lvD);
			_dBtn.enable = true;
			_cBtn = new LButton(symbolSkin._lvC);
			_cBtn.enable = true;
			_bBtn = new LButton(symbolSkin._lvB);
			_bBtn.enable = true;
			_aBtn = new LButton(symbolSkin._lvA);
			_aBtn.enable = true;
			_sBtn = new LButton(symbolSkin._lvS);
			_sBtn.enable = true;
			selectTabButton(_sBtn);
			selectType = S_TYPE;
			addEvtListener();
		}
		
		public function addEvtListener():void
		{
			_dBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_cBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_bBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_aBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			_sBtn.addEventListener(MouseEvent.CLICK,clickHandler);
		}
		
		public function removeEvtListener():void
		{
			_dBtn.removeEventListener(MouseEvent.CLICK,clickHandler);
			_cBtn.removeEventListener(MouseEvent.CLICK,clickHandler);
			_bBtn.removeEventListener(MouseEvent.CLICK,clickHandler);
			_aBtn.removeEventListener(MouseEvent.CLICK,clickHandler);
			_sBtn.removeEventListener(MouseEvent.CLICK,clickHandler)
		}
		
		public function destroyView():void
		{
			removeEvtListener();
			
		}
		private function clickHandler(event:MouseEvent):void
		{
			if(selectBtn)
			{
				selectBtn.enable = true;
				selectBtn.setStatus(LButton.UP);
			}
			selectTabButton( event.target as LButton ); 
			switch(selectBtn)
			{
				case _dBtn:
					selectType = D_TYPE;
					break;
				case _cBtn:
					selectType = C_TYPE;
					break;
				case _bBtn:
					selectType = B_TYPE;
					break;
				case _aBtn:
					selectType = A_TYPE;
					break;
				case _sBtn:
					selectType = S_TYPE;
					break;
			}
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		/**
		 *选择某个tab button 
		 * @param lBtn
		 * 
		 */		
		public function selectTabButton(lBtn :LButton):void
		{
			selectBtn = lBtn;
			if(selectBtn)
			{
				selectBtn.enable = false;
				selectBtn.setStatus(LButton.SELECT);
			}
		}
		/**
		 * 设置按钮选中哪个 
		 * @param $lv
		 * 
		 */
		public function selectButtonByID($lv:int):void
		{
			switch($lv)
			{
				case 1:
					selectTabButton(_dBtn);
					break;
				case 2:
					selectTabButton(_cBtn);
					break;
				case 3:
					selectTabButton(_bBtn);
					break;
				case 4:
					selectTabButton(_aBtn);
					break;
				case 5:
					selectTabButton(_sBtn);
					break;
			}
		}
	}
}